//
//  GetXMLObject.m
//  和讯
//
//  Created by 8003 on 15/11/16.
//  Copyright © 2015年 jianku. All rights reserved.
//

#import "GetXMLObject.h"
#import "XMLModel.h"
#import "GDataXMLNode.h"
#import "NEWSModel.h"
#import "StockModel.h"
@interface GetXMLObject ()

@end

@implementation GetXMLObject

- (void )getXMLData:(NSString *)urlString
{
    
    NSURL* url = [NSURL URLWithString:urlString];
    NSData* data = [NSData dataWithContentsOfURL:url];
    [self getXMLTitleModelArray:data];
    
    
}

-(void)getXMLTitleModelArray:(NSData *)data
{
    
    NSMutableArray* tempArray = [NSMutableArray new];
    //2.把XML数据整个转换成文档对象
    GDataXMLDocument* xmlDocument = [[GDataXMLDocument alloc]initWithData:data options:XML_PARSE_NOBLANKS | XML_PARSE_NOCDATA error:nil];
    
    //从文档对象获取根节点
    GDataXMLElement* doc = [xmlDocument rootElement];
    
    //在节点下获取所有User节点
    NSArray* all_doc_elements = [doc elementsForName:@"news"];
    
    //3.3.遍历all_doc_elements数组，循环解析每个User节点
    for (GDataXMLElement* docElement in all_doc_elements)
    {
        //首先要解析出name节点
        GDataXMLElement* ID = [docElement elementsForName:@"id"].firstObject;
        //再从name节点解析出title节点
        GDataXMLElement* title = [docElement elementsForName:@"title"].firstObject;
        
        GDataXMLElement* date = [docElement elementsForName:@"time"].firstObject;
        
        GDataXMLElement* subtype = [docElement elementsForName:@"subtype"].firstObject;
        
        GDataXMLElement* content = [docElement elementsForName:@"content"].firstObject;
        
        GDataXMLElement* url = [docElement elementsForName:@"url"].firstObject;
        
        GDataXMLElement* place = [docElement elementsForName:@"place"].firstObject;
        
        GDataXMLElement* imgStrs = [docElement elementsForName:@"img"].firstObject;
        
        //创建title模型对象并用解析得到的数据给他赋值
        XMLModel *aNew = [XMLModel new];
        if (![ID.stringValue isEqualToString:@""]) {
        aNew.ID = ID.stringValue;
        aNew.title = title.stringValue;
        aNew.date = date.stringValue;
        aNew.subtype = [subtype.stringValue integerValue];
        aNew.content = content.stringValue;
        aNew.url = url.stringValue;
        aNew.place = [place.stringValue integerValue];
        aNew.imgStrs = imgStrs.stringValue;
        [tempArray addObject:aNew];
        }else
        {
            continue;
        }
    }
    self.resultArray = [[NSArray alloc]initWithArray:tempArray];
    NSLog(@"xml.resultArray = %@",self.resultArray);
}

-(NSArray* )getOtherNewsModelArray:(NSString *)urlStr
{
    NSString* str = @"http://wiapi.hexun.com/news/gethp2.0.php?id=";
    
    NSURL* url = [NSURL URLWithString:[str stringByAppendingString:urlStr]];
    NSData* data = [NSData dataWithContentsOfURL:url];
    NSLog(@"data : %@",data);
    
    NSMutableArray* tempArray = [NSMutableArray new];
    //2.把XML数据整个转换成文档对象
    GDataXMLDocument* xmlDocument = [[GDataXMLDocument alloc]initWithData:data options:XML_PARSE_NOBLANKS | XML_PARSE_NOCDATA error:nil];
    
    //从文档对象获取根节点
    GDataXMLElement* doc = [xmlDocument rootElement];
    
    //在节点下获取所有User节点
    NSArray* all_doc_elements = [doc elementsForName:@"news"];
    
    //3.3.遍历all_doc_elements数组，循环解析每个User节点
    for (GDataXMLElement* docElement in all_doc_elements)
    {
        //首先要解析出name节点
        GDataXMLElement* ID = [docElement elementsForName:@"id"].firstObject;
        //再从name节点解析出title节点
        GDataXMLElement* title = [docElement elementsForName:@"title"].firstObject;
        
        GDataXMLElement* date = [docElement elementsForName:@"time"].firstObject;
        
        GDataXMLElement* subtype = [docElement elementsForName:@"subtype"].firstObject;
        
        GDataXMLElement* content = [docElement elementsForName:@"content"].firstObject;
        
        GDataXMLElement* url = [docElement elementsForName:@"url"].firstObject;
        
        GDataXMLElement* place = [docElement elementsForName:@"place"].firstObject;
        
        GDataXMLElement* imgStrs = [docElement elementsForName:@"img"].firstObject;
        
        //创建title模型对象并用解析得到的数据给他赋值
        XMLModel *aNew = [XMLModel new];
        if (![ID.stringValue isEqualToString:@""])
        {
        aNew.ID = ID.stringValue;
        aNew.title = title.stringValue;
        aNew.date = date.stringValue;
        aNew.subtype = [subtype.stringValue integerValue];
        aNew.content = content.stringValue;
        aNew.url = url.stringValue;
        aNew.place = [place.stringValue integerValue];
        aNew.imgStrs = imgStrs.stringValue;
        [tempArray addObject:aNew];
        }
        else
        {
            continue;
        }
    }
    
    NSArray* array = [[NSArray alloc]initWithArray:tempArray];
    NSLog(@"Array = %@",array);
    return array;
}

-(NEWSModel *)getSomeoneNewFromNewsID:(NSString *)ID
{
    NSString* string = [NSString stringWithFormat:@"http://wiapi.hexun.com/news/gethp.php?id="];
    NSString* requestUrl = [string stringByAppendingString:ID];
    NSURL* url = [NSURL URLWithString:requestUrl];
    NSData* data = [NSData dataWithContentsOfURL:url];
    NSLog(@"data : %@",data);
    
    //GBK编码代号
    NSStringEncoding GBKEncoding = CFStringConvertEncodingToNSStringEncoding(kCFStringEncodingGB_18030_2000);
    
    //使用GBK编码创建XML字符串
    NSString *xmlString = [[NSString alloc] initWithData:data encoding:GBKEncoding];
    
    //去除字符串中的<?xml version="1.0" encoding="GBK"?>部分
    NSString* str1 = @"<?xml version=\"1.0\" encoding=\"GBK\"?>";
    NSString* str = [xmlString stringByReplacingCharactersInRange:NSMakeRange(0, str1.length+1) withString:@""];
    
    //把XML数据整个转换成文档对象
    GDataXMLDocument* xmlDocument = [[GDataXMLDocument alloc]initWithXMLString:str options:XML_PARSE_NOBLANKS | XML_PARSE_NOCDATA error:nil];
    //    GDataXMLDocument* xmlDocument = [[GDataXMLDocument alloc]initWithData:data options:XML_PARSE_NOBLANKS | XML_PARSE_NOCDATA error:nil];
    
    //从文档对象获取根节点
    GDataXMLElement* doc = [xmlDocument rootElement];
    
    //在节点下获取所有User节点
    NSArray* all_doc_elements = [doc elementsForName:@"news"];
    GDataXMLNode* IDNode = [all_doc_elements.firstObject attributeForName:@"id"];
    
    //再从name节点解析出title节点
    GDataXMLElement* title = [all_doc_elements.firstObject elementsForName:@"title"].firstObject;
    
    GDataXMLElement* keyword = [all_doc_elements.firstObject elementsForName:@"keyword"].firstObject;
    
    GDataXMLElement* media = [all_doc_elements.firstObject elementsForName:@"media"].firstObject;
    
    GDataXMLElement* content = [all_doc_elements.firstObject elementsForName:@"content"].firstObject;
    
    GDataXMLElement* author = [all_doc_elements.firstObject elementsForName:@"author"].firstObject;
    
    GDataXMLElement* abstract = [all_doc_elements.firstObject elementsForName:@"abstract"].firstObject;
    
    GDataXMLElement* matchpic = [all_doc_elements.firstObject elementsForName:@"matchpic"].firstObject;
    
    GDataXMLElement* relatednews = [all_doc_elements.firstObject elementsForName:@"relatednews"].firstObject;
    
    NEWSModel *aNew = [NEWSModel new];
    aNew.ID = IDNode.stringValue;
    aNew.title = title.stringValue;
    aNew.keyword = keyword.stringValue;
    aNew.media = media.stringValue;
    aNew.content = content.stringValue;
    aNew.author = author.stringValue;
    aNew.abstract = abstract.stringValue;
    aNew.matchpic = matchpic.stringValue;
    aNew.relatednews = relatednews.stringValue;
    
    NSLog(@"xml.resultArray = %@",aNew);
    return aNew;
    
}


- (NSArray *)getStockArrayFromIDArray:(NSArray *)ID sort:(NSInteger)number type:(NSInteger)num
{
    NSMutableString* codeStr = [NSMutableString new];
    for (int i = 0; i < ID.count; i++) {
        if (i == 0)
        {
            [codeStr appendString:ID.firstObject];
        }
        else
        {
            [codeStr appendFormat:@",%@",ID[i]];
        }
    }
    NSMutableArray* stockModelArr = [NSMutableArray new];
    
    NSString* str = @"http://quote.wiapi.hexun.com/bstock/select?";
    
    NSString *param=[str stringByAppendingFormat:@"code=%@&sort=%ld&type=%ld",codeStr,number,num];
    NSURL *URL=[NSURL URLWithString:param];//不需要传递参数
    
    NSData* data = [NSData dataWithContentsOfURL:URL];
    NSData* data1 = [data subdataWithRange:NSMakeRange(12, data.length-12)];
    NSString* stockArrStr = [[NSString alloc]initWithData:data1 encoding:NSUTF8StringEncoding];
    NSLog(@"%@",stockArrStr);
    NSArray* stocks = [self getStrArrFrom:stockArrStr using:@";"];
    for (NSString* str in stocks)
    {
        NSArray* stockInfos = [self getStrArrFrom:str using:@","];
        StockModel* stockModel = [StockModel new];
        stockModel.stockID = stockInfos[0];
        stockModel.stockCode = stockInfos[2];
        stockModel.stockName = stockInfos[3];
        stockModel.newest = stockInfos[4];
        stockModel.upsAndDowns = stockInfos[5];
        stockModel.amountofIncrease = stockInfos[6];
        stockModel.handOFF = stockInfos[7];
        stockModel.tradingVolume = stockInfos[8];
        stockModel.tradingAccount = stockInfos[9];
        stockModel.quantityRelativeRatio = stockInfos[10];
        stockModel.swing = stockInfos[11];            //振幅
        stockModel.yesterAccount = stockInfos[12];  //昨收
        stockModel.UpSpeed = stockInfos[13];
        [stockModelArr addObject:stockModel];
    }
    NSArray* array = [NSArray arrayWithArray:stockModelArr];
    return array;
}


-(NSArray *)getStockArrayFromBlock:(NSInteger)BlockNumber sort:(NSInteger)number type:(NSInteger)num start:(NSInteger)startNumber end:(NSInteger)endNumber
{
    NSString* str = @"http://quote.wiapi.hexun.com/bstock/riseFall?";
    NSMutableArray* stockModelArr = [NSMutableArray new];
    NSString *param=[str stringByAppendingFormat:@"block=%ld&sort=%ld&type=%ld&start=%ld&end=%ld",BlockNumber,number,num,startNumber,endNumber];
    NSURL *URL=[NSURL URLWithString:param];
    NSData* data = [NSData dataWithContentsOfURL:URL];
    NSData* data1 = [data subdataWithRange:NSMakeRange(12, data.length-12)];
    NSString* stockArrStr = [[NSString alloc]initWithData:data1 encoding:NSUTF8StringEncoding];
    
    NSArray* stocks = [self getStrArrFrom:stockArrStr using:@";"];
    for (NSString* str in stocks)
    {
        NSArray* stockInfos = [self getStrArrFrom:str using:@","];
        StockModel* stockModel = [StockModel new];
        stockModel.stockID = stockInfos[0];
        stockModel.stockCode = stockInfos[2];
        stockModel.stockName = stockInfos[3];
        stockModel.newest = stockInfos[4];
        stockModel.upsAndDowns = stockInfos[5];
        stockModel.amountofIncrease = stockInfos[6];
        stockModel.handOFF = stockInfos[7];
        stockModel.tradingVolume = stockInfos[8];
        stockModel.tradingAccount = stockInfos[9];
        stockModel.quantityRelativeRatio = stockInfos[10];
        stockModel.swing = stockInfos[11];            //振幅
        stockModel.yesterAccount = stockInfos[12];  //昨收
        stockModel.UpSpeed = stockInfos[13];
        [stockModelArr addObject:stockModel];
    }
    NSArray* array = [NSArray arrayWithArray:stockModelArr];
    return array;
}

-(NSArray *)getStockInfoArrayFromStockID:(NSString *)ID
{
    NSMutableArray* tempArr = [NSMutableArray new];
    NSString* string = [NSString stringWithFormat:@"http://quote.wiapi.hexun.com/bstock/stockShare?code="];
    NSString* requestUrl = [string stringByAppendingString:ID];
    NSURL* url = [NSURL URLWithString:requestUrl];
    NSData* data = [NSData dataWithContentsOfURL:url];
    NSData* data1 = [data subdataWithRange:NSMakeRange(8, data.length-8)];
    NSString* stockArrStr = [[NSString alloc]initWithData:data1 encoding:NSUTF8StringEncoding];
    NSLog(@"data : %@",data1);
    
    NSArray* stock = [self getStrArrFrom:stockArrStr using:@";"];
    
    for (int i = 0; i < stock.count; i++)
    {
        if (i == 0)
        {
            NSArray* stockInfo = [self getStrArrFrom:stock[0] using:@","];
            StockModel* stockModel = [StockModel new];
            stockModel.stockID = stockInfo[0];
            stockModel.stockCode = stockInfo[2];
            stockModel.stockName = stockInfo[3];
            stockModel.newest = stockInfo[4];
            stockModel.upsAndDowns = stockInfo[5];
            stockModel.amountofIncrease = stockInfo[6];
            stockModel.hightest = stockInfo[7];
            stockModel.opening = stockInfo[8];
            stockModel.lowest = stockInfo[9];
            stockModel.median = stockInfo[10];
            stockModel.handOFF = stockInfo[11];
            stockModel.tradingAccount = stockInfo[12];
            stockModel.capitalStock = stockInfo[13];
            stockModel.marketValue = stockInfo[14];
            stockModel.priceEarning = stockInfo[15];
            stockModel.circulate = stockInfo[16];
            [tempArr addObject:stockModel];
        }
        else
        {
            NSArray* stockTimeTradingArr = [self getStrArrFrom:stock[i] using:@","];
            StockModel* stockModel = [StockModel new];
            stockModel.timePoint = stockTimeTradingArr[0];
            stockModel.tradingPrice = stockTimeTradingArr[1];
            stockModel.tradingPriceSum = stockTimeTradingArr[2];
            stockModel.tradingStockSum = stockTimeTradingArr[3];
            [tempArr addObject:stockModel];
        }
    }
    
    NSArray* array = [NSArray arrayWithArray:tempArr];
    return array;
}

-(NSArray *)getAllAroundtheWorldStock
{
    NSMutableArray* tempArray = [NSMutableArray new];
    NSString* string = [NSString stringWithFormat:@"http://wiapi.hexun.com/hq/gi.php"];
    NSURL* url = [NSURL URLWithString:string];
    NSData* data = [NSData dataWithContentsOfURL:url];
    NSLog(@"data : %@",data);
    
    //GBK编码代号
    NSStringEncoding GBKEncoding = CFStringConvertEncodingToNSStringEncoding(kCFStringEncodingGB_18030_2000);
    
    //使用GBK编码创建XML字符串
    NSString *xmlString = [[NSString alloc] initWithData:data encoding:GBKEncoding];
    
    //去除字符串中的<?xml version="1.0" encoding="GB2312"?>部分
    NSString* str1 = @"<?xml version=\"1.0\" encoding=\"GB2312\"?>";
    NSString* str = [xmlString stringByReplacingCharactersInRange:NSMakeRange(0, str1.length+1) withString:@""];
    //把XML数据整个转换成文档对象
    GDataXMLDocument* xmlDocument = [[GDataXMLDocument alloc]initWithXMLString:str options:XML_PARSE_NOBLANKS | XML_PARSE_NOCDATA error:nil];
    //    GDataXMLDocument* xmlDocument = [[GDataXMLDocument alloc]initWithData:data options:XML_PARSE_NOBLANKS | XML_PARSE_NOCDATA error:nil];
    
    //从文档对象获取根节点
    GDataXMLElement* newDataSet = [xmlDocument rootElement];
    
    //在节点下获取所有table节点
    NSArray* all_newDataSet_elements = [newDataSet elementsForName:@"table"];
    
    for (GDataXMLElement* newDataSetElement in all_newDataSet_elements)
    {
        //首先要解析出name节点
        
        
        GDataXMLElement* fld_subarea = [newDataSetElement elementsForName:@"fld_description"].firstObject;
        
        GDataXMLElement* fld_index = [newDataSetElement elementsForName:@"fld_index"].firstObject;
        //再从name节点解析出title节点
        GDataXMLElement* fld_value = [newDataSetElement elementsForName:@"fld_value"].firstObject;
        
        GDataXMLElement* fld_rate = [newDataSetElement elementsForName:@"fld_rate"].firstObject;
        
        GDataXMLElement* fld_change = [newDataSetElement elementsForName:@"fld_change"].firstObject;
        
        GDataXMLElement* fld_time = [newDataSetElement elementsForName:@"fld_time"].firstObject;
        
        GDataXMLElement* fld_url = [newDataSetElement elementsForName:@"fld_url"].firstObject;
        
        //创建stockModel模型对象并用解析得到的数据给他赋值
        StockModel *aStock = [StockModel new];
        aStock.fld_subareas = fld_subarea.stringValue;
        aStock.stockName = fld_index.stringValue;
        aStock.upsAndDowns = fld_change.stringValue;
        aStock.amountofIncrease = fld_rate.stringValue;
        aStock.fld_time = fld_time.stringValue;
        aStock.fld_url = fld_url.stringValue;
        aStock.newest = fld_value.stringValue;
        
        [tempArray addObject:aStock];
    }
    NSArray* array = [[NSArray alloc]initWithArray:tempArray];
    return array;
}

-(NSArray *)getOutFutureGoodsArray
{
    NSMutableArray* tempArr = [NSMutableArray new];
    NSString* string = [NSString stringWithFormat:@"http://wiapi.hexun.com/hq/wft.php"];
    NSURL* url = [NSURL URLWithString:string];
    NSString* str = [NSString stringWithContentsOfURL:url encoding:NSUTF8StringEncoding error:nil];
    NSArray* strArr = [self getStrArrFrom:str using:@"|"];
    for (NSString* str1 in strArr)
    {
        NSArray* futuerGoodsInfo = [self getStrArrFrom:str1 using:@","];
        StockModel* stockModel = [StockModel new];
        stockModel.fld_index = futuerGoodsInfo[1];
        stockModel.fld_value = futuerGoodsInfo[2];
        stockModel.fld_change = futuerGoodsInfo[8];
        stockModel.fld_rate = futuerGoodsInfo[13];
        stockModel.stockName = futuerGoodsInfo[1];
        stockModel.newest = futuerGoodsInfo[2];
        stockModel.upsAndDowns = futuerGoodsInfo[8];
        stockModel.amountofIncrease = futuerGoodsInfo[13];
        stockModel.fld_time = futuerGoodsInfo[14];
        [tempArr addObject:stockModel];
    }
    NSArray* array = [NSArray arrayWithArray:tempArr];
    return array;
}

-(NSArray *)getExchangeQuotationsArray
{
    
    NSMutableArray* tempArray = [NSMutableArray new];
    NSString* string = [NSString stringWithFormat:@"http://wiapi.hexun.com/hq/fxquote.php"];
    NSURL* url = [NSURL URLWithString:string];
    NSData* data = [NSData dataWithContentsOfURL:url];
    NSLog(@"data : %@",data);
    
    //GBK编码代号
    NSStringEncoding GBKEncoding = CFStringConvertEncodingToNSStringEncoding(kCFStringEncodingGB_18030_2000);
    
    //使用GBK编码创建XML字符串
    NSString *xmlString = [[NSString alloc] initWithData:data encoding:GBKEncoding];
    
    //去除字符串中的<?xml version="1.0" encoding="GB2312"?>部分
    NSString* str1 = @"<?xml version=\"1.0\" encoding=\"GB2312\"?>";
    NSString* str = [xmlString stringByReplacingCharactersInRange:NSMakeRange(0, str1.length+1) withString:@""];
    
    //把XML数据整个转换成文档对象
    GDataXMLDocument* xmlDocument = [[GDataXMLDocument alloc]initWithXMLString:str options:XML_PARSE_NOBLANKS | XML_PARSE_NOCDATA error:nil];

    
    //从文档对象获取根节点
    GDataXMLElement* newDataSet = [xmlDocument rootElement];
    
    //在节点下获取所有table节点
    NSArray* all_newDataSet_elements = [newDataSet elementsForName:@"Table"];
    
    for (GDataXMLElement* newDataSetElement in all_newDataSet_elements)
    {
        //解析出节点
        GDataXMLElement* Name = [newDataSetElement elementsForName:@"Name"].firstObject;
        
        GDataXMLElement* Price = [newDataSetElement elementsForName:@"Price"].firstObject;
        
        GDataXMLElement* UpDownRate = [newDataSetElement elementsForName:@"UpDownRate"].firstObject;
        
        GDataXMLElement* UpdownPrice = [newDataSetElement elementsForName:@"UpDownPrice"].firstObject;
        
        GDataXMLElement* Time = [newDataSetElement elementsForName:@"Time"].firstObject;
        
        //创建stockModel模型对象并用解析得到的数据给他赋值
        StockModel *aStock = [StockModel new];
        aStock.fld_index = Name.stringValue;
        aStock.stockName = Name.stringValue;
        aStock.fld_change = UpdownPrice.stringValue;
        aStock.upsAndDowns = UpdownPrice.stringValue;
        aStock.fld_rate = UpDownRate.stringValue;
        aStock.amountofIncrease = UpDownRate.stringValue;
        aStock.fld_time = Time.stringValue;
        aStock.fld_value = Price.stringValue;
        aStock.newest = Price.stringValue;
        
        [tempArray addObject:aStock];
    }
    NSArray* array = [[NSArray alloc]initWithArray:tempArray];
    return array;
    
}


-(NSArray *)getFundNetValueArray
{
    
    NSURL* url = [NSURL URLWithString:[NSString stringWithFormat:@"http://wiapi.hexun.com/fund/stocknv.php"]];
    NSData* data = [NSData dataWithContentsOfURL:url];
    NSLog(@"data : %@",data);
    
    NSMutableArray* tempArray = [NSMutableArray new];
    //2.把XML数据整个转换成文档对象
    GDataXMLDocument* xmlDocument = [[GDataXMLDocument alloc]initWithData:data options:XML_PARSE_NOBLANKS | XML_PARSE_NOCDATA error:nil];
    
    //从文档对象获取根节点
    GDataXMLElement* doc = [xmlDocument rootElement];
    
    //在节点下获取所有User节点
    NSArray* all_doc_elements = [doc elementsForName:@"data"];
    
    //3.3.遍历all_doc_elements数组，循环解析每个User节点
    for (GDataXMLElement* docElement in all_doc_elements)
    {
        //首先要解析出节点
        GDataXMLElement* name = [docElement elementsForName:@"name"].firstObject;
        //再从name节点解析出节点
        GDataXMLElement* time = [docElement elementsForName:@"time"].firstObject;
        
        GDataXMLElement* unit = [docElement elementsForName:@"unit"].firstObject;
        
        GDataXMLElement* net = [docElement elementsForName:@"net"].firstObject;
        
        GDataXMLElement* rate = [docElement elementsForName:@"rate"].firstObject;
        
        //创建stockModel模型对象并用解析得到的数据给他赋值
        StockModel *OneInfo = [StockModel new];
        OneInfo.stockName = name.stringValue;
        OneInfo.upsAndDowns = unit.stringValue;
        OneInfo.amountofIncrease = rate.stringValue;
        OneInfo.fld_time = time.stringValue;
        OneInfo.newest = net.stringValue;
        [tempArray addObject:OneInfo];
    }
    NSArray* array = [NSArray arrayWithArray:tempArray];
    return array;
}


-(NSArray *)getPhotoNEWSArrayFromBlockID:(NSInteger)number
{
    NSMutableArray* tempArr = [NSMutableArray new];
    NSString* str = [NSString stringWithFormat:@"http://wiapi.hexun.com/news/gethp.php?id="];
    NSURL* url = [NSURL URLWithString:[str stringByAppendingString:[NSString stringWithFormat:@"%ld",number]]];
    NSData* data = [NSData dataWithContentsOfURL:url];
    
    GDataXMLDocument* xmlDocument = [[GDataXMLDocument alloc]initWithData:data options:XML_PARSE_NOBLANKS | XML_PARSE_NOCDATA error:nil];
    
    //从文档对象获取根节点
    GDataXMLElement* Data = [xmlDocument rootElement];
    
    //在节点下获取所有User节点
    NSArray* all_data_elements = [Data elementsForName:@"news"];
    
    //3.3.遍历all_doc_elements数组，循环解析每个User节点
    for (GDataXMLElement* dataElement in all_data_elements)
    {
        //首先要解析出节点
        GDataXMLElement* title = [dataElement elementsForName:@"title"].firstObject;
        //再从name节点解析出节点
        GDataXMLElement* content = [dataElement elementsForName:@"pics_abstract"].firstObject;
        
        GDataXMLElement* matchpic = [dataElement elementsForName:@"pics"].firstObject;
        
        
        //创建NEWSModel模型对象并用解析得到的数据给他赋值
        NEWSModel *OneInfo = [NEWSModel new];
        OneInfo.title = title.stringValue;
        OneInfo.content = content.stringValue;
        OneInfo.matchpic = matchpic.stringValue;
        [tempArr addObject:OneInfo];
    }
    NSArray* array = [NSArray arrayWithArray:tempArr];
    return array;
}

-(NSArray *)getVideoNEWSArrayFromBlockID:(NSInteger)number
{
    NSMutableArray* tempArr = [NSMutableArray new];
    NSString* str = [NSString stringWithFormat:@"http://wiapi.hexun.com/news/gethp.php?id="];
    NSURL* url = [NSURL URLWithString:[str stringByAppendingString:[NSString stringWithFormat:@"%ld",number]]];
    NSData* data = [NSData dataWithContentsOfURL:url];
    
    GDataXMLDocument* xmlDocument = [[GDataXMLDocument alloc]initWithData:data options:XML_PARSE_NOBLANKS | XML_PARSE_NOCDATA error:nil];
    
    //从文档对象获取根节点
    GDataXMLElement* doc = [xmlDocument rootElement];
    
    //在节点下获取所有User节点
    NSArray* all_doc_elements = [doc elementsForName:@"news"];
    
    //3.3.遍历all_doc_elements数组，循环解析每个User节点
    for (GDataXMLElement* docElement in all_doc_elements)
    {
        //解析出节点
        GDataXMLElement* ID = [docElement elementsForName:@"id"].firstObject;
        
        GDataXMLElement* title = [docElement elementsForName:@"title"].firstObject;
        
        GDataXMLElement* matchpic = [docElement elementsForName:@"img"].firstObject;
        
        
        //创建NEWSModel模型对象并用解析得到的数据给他赋值
        NEWSModel *OneInfo = [NEWSModel new];
        OneInfo.ID = ID.stringValue;
        OneInfo.title = title.stringValue;
        OneInfo.matchpic = matchpic.stringValue;
        [tempArr addObject:OneInfo];
    }
    NSArray* array = [NSArray arrayWithArray:tempArr];
    return array;
}

-(NSURL *)getVideoNewsURLFromVideoNEWSID:(NSString *)ID
{
    NSString* string = [NSString stringWithFormat:@"http://wiapi.hexun.com/news/gethp.php?id="];
    NSURL* url = [NSURL URLWithString:[string stringByAppendingString:ID]];
    NSData* data = [NSData dataWithContentsOfURL:url];
    
    //GBK编码代号
    NSStringEncoding GBKEncoding = CFStringConvertEncodingToNSStringEncoding(kCFStringEncodingGB_18030_2000);
    
    //使用GBK编码创建XML字符串
    NSString *xmlString = [[NSString alloc] initWithData:data encoding:GBKEncoding];
    
    //去除字符串中的<?xml version="1.0" encoding="GBK"?>部分
    NSString* str1 = @"<?xml version=\"1.0\" encoding=\"GBK\"?>";
    NSString* str = [xmlString stringByReplacingCharactersInRange:NSMakeRange(0, str1.length+1) withString:@""];
    
    GDataXMLDocument* xmlDocument = [[GDataXMLDocument alloc]initWithXMLString:str options:XML_PARSE_NOBLANKS | XML_PARSE_NOCDATA error:nil];
    //    GDataXMLDocument* xmlDocument = [[GDataXMLDocument alloc]initWithData:data options:XML_PARSE_NOBLANKS | XML_PARSE_NOCDATA error:nil];
    
    //从文档对象获取根节点
    GDataXMLElement* Data = [xmlDocument rootElement];
    
    NSArray* all_Data_elements = [Data elementsForName:@"News"];
    //在节点下获取所有News节点
    GDataXMLElement* docElement = all_Data_elements.firstObject;
    GDataXMLElement* URL = [docElement elementsForName:@"videourl"].firstObject;
    
    return [NSURL URLWithString:URL.stringValue];
    
}



-(NSArray *)getStrArrFrom:(NSString *)string using:(NSString *)cutStr
{
    
    NSMutableArray* tempArr = [NSMutableArray new];
    while([string rangeOfString:cutStr].location != NSNotFound)
    {
        NSRange range = [string rangeOfString:cutStr];
        NSString*str1 = [string substringWithRange:NSMakeRange(0, range.location)];
        [tempArr addObject:str1];
        // string = [string substringWithRange:NSMakeRange(range.location+1, string.length)];
        string = [string substringFromIndex:range.location+1];
    }
    [tempArr addObject:string];
    return tempArr;
}

-(NSString *)stringFromArray:(NSArray *)arr with:(NSString *)str
{
    NSMutableString* str1 = [NSMutableString new];
    [str1 appendString:arr.firstObject];
    for (int i = 1 ; i < arr.count; i++)
    {
        NSString* s1 = [str stringByAppendingString:arr[1]];
        [str1 appendString:s1];
    }
    NSString* s2 = [NSString stringWithString:str1];
    return s2;
}

-(NSString *)deletelHTMLNode:(NSString *)str
{
    NSRegularExpression* regularExpretion = [NSRegularExpression regularExpressionWithPattern:@"<[^>]*>|/n" options:0 error:nil];
    str = [regularExpretion stringByReplacingMatchesInString:str options:NSMatchingReportProgress range:NSMakeRange(0, str.length) withTemplate:@"-"];
    
    regularExpretion = [NSRegularExpression regularExpressionWithPattern:@"-{1,}" options:0 error:nil];
    str = [regularExpretion stringByReplacingMatchesInString:str options:NSMatchingReportProgress range:NSMakeRange(0, str.length) withTemplate:@""];
    return str;
}

@end
